
#include "member_BMesh.h"

using namespace BWE;

member_BMesh::member_BMesh(BMesh* mesh)
{
	boss = mesh;
}
member_BMesh::~member_BMesh()
{

}

void member_BMesh::slotFreshFaceOctTree()
{
	BSpace treeSpace = faceOctTree->space();
	const BSpace& space = boss->space();
	if (treeSpace.contain(space))
		return;
	faceOctTree->reset(space);
	if (faces)
	{
		for (int i = 0; i < faces->size(); i++)
		{
			const BFace& face = (*faces)[i];
			const BVector& va = (*vertices)[face.a()];
			const BVector& vb = (*vertices)[face.b()];
			const BVector& vc = (*vertices)[face.c()];
			BSpace space = va;
			space.expand(vb);
			space.expand(vc);
			auto item = faceOctTree->create(space);
			item->append(face);
		}
	}
	else
	{
		for (int i = 0; i < vertices->size(); i += 3)
		{
			BFace face(i, i + 1, i + 2);
			const BVector& va = (*vertices)[face.a()];
			const BVector& vb = (*vertices)[face.b()];
			const BVector& vc = (*vertices)[face.c()];
			BSpace space = va;
			space.expand(vb);
			space.expand(vc);
			auto item = faceOctTree->create(space);
			item->append(face);
		}
	}
}